<?php
/**
 * KePHP, Keep PHP easy!
 */

namespace CSService\Model\Task;

use Ke\Adm\Model;
use Ke\Adm\Sql\QueryBuilder;

/**
 * Class Task_Log
 * tableName task_log
 *
 * // class properties
 * @property int   $id         id
 * @property int   $user_id    用户id
 * @property int   $server_id  服务器id
 * @property int   $project_id 项目id
 * @property int   $command_id 命令id
 * @property mixed $misc       命令参数
 * @property int   $used_time  耗时
 * @property int   $created_at 创建时间
 * // class properties
 */
class Task_Log extends Model
{

	protected static $pk = 'id';

	protected static $pkAutoInc = true;

	protected static $columns = [
	];

	protected static $queries = [
		'list' => [
			'select' => 'tb1.id, tb1.created_at, tb2.name as project_name, tb3.lan_ip, tb4.name as command_name, tb5.login_id as user_name',
			'order'  => 'tb1.id DESC',
			'join'   => [
				[QueryBuilder::LEFT_JOIN, 'project.id', 'tb1.project_id'],
				[QueryBuilder::LEFT_JOIN, 'server.id', 'tb1.server_id'],
				[QueryBuilder::LEFT_JOIN, 'command.id', 'tb1.command_id'],
				[QueryBuilder::LEFT_JOIN, 'user.id', 'tb1.user_id'],
			],
		],
	];

	public static function dbColumns()
	{
		// database columns
		// generated as 2016-02-01 22:52:19
		return [
			'id'         => ['int' => 1, 'pk' => 1, 'autoInc' => 1],
			'user_id'    => ['label' => '用户id', 'int' => 1, 'default' => 0],
			'server_id'  => ['label' => '服务器id', 'int' => 1, 'default' => 0],
			'project_id' => ['label' => '项目id', 'int' => 1, 'default' => 0],
			'command_id' => ['label' => '命令id', 'int' => 1, 'default' => 0],
			'misc'       => ['label' => '命令参数'],
			'used_time'  => ['label' => '耗时', 'timestamp' => 1],
			'created_at' => ['label' => '创建时间', 'timestamp' => 1, self::ON_CREATE => 'now'],
		];
		// database columns
	}

}
